package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsOrder;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsOrderMapper extends BaseMapper<DtsOrder> {

    /**
     * 统计最近多少天内的订单的增长量和当天订单的总金额
     * @return
     */
    @Select("select DATE_FORMAT(a.add_time, \"%Y-%m-%d\") as dayStr, " +
            " count(*) as cnts, " +
            " sum(actual_price) as amts " +
            "from dts_order a " +
            "where a.deleted=0 " +
            "group by DATE_FORMAT(a.add_time, \"%Y-%m-%d\") ")
    public List<DayStatis> staticsIncresOrderCnt();


    /**
     * 按照分类, 统计每个分类中商品的销售额
     */
    @Select("select d.`name`, sum(a.price) as value " +
            "from dts_order_goods a " +
            "left join dts_order b on a.order_id = b.id " +
            "left join dts_goods c on a.goods_id = c.id  " +
            "left join dts_category d on c.category_id = d.id " +
            "where a.deleted=0 and b.deleted=0 and d.`name` is not null " +
            "group by d.`name`")
    public List<CategorySellAmts> categorySell();


}
